package com.aluka.nirvana.framework.wechat.mina.model;

import com.google.common.collect.Maps;
import lombok.Data;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.util.Map;

/**
 * 微信小程序服务端接口参数基类
 * @author gongli
 * @since 2020/4/7 19:14
 */
@Data
public abstract class MinaBasicRequest {

    /**
     * 接口调用凭证
     */
    private String access_token;

    /**
     * 将当前实体转换为Map
     * @return java.util.Map
     */
    public Map<String,Object> covertMap(){
        Field[] fields = this.getClass().getDeclaredFields();
        Map<String,Object> poMap = Maps.newHashMap();
        for (Field field : fields) {
            ReflectionUtils.makeAccessible(field);
            Object fieldValue = ReflectionUtils.getField(field, this);
            if(null != fieldValue){
                poMap.put(field.getName(),fieldValue);
            }
        }
        return poMap;
    }

}
